function GSOption () {
	// Background image
	var splashImageHandle;
	var panelImageHandle;
	var qualityButtonHandle;
	
	var progressBarImageHandle;
	
	var BACKGROUND_BLUR_R = 0;
	var BACKGROUND_BLUR_G = 1;
	var BACKGROUND_BLUR_B = 2;
	var BACKGROUND_BLUR_ALPHA = 0.6;
	
	var PANEL_X = 415;
	var PANEL_Y = 60;
	var PANEL_W = 450;
	var PANEL_H = 600;
	
	var FADE_SPEED = 4;
	
	
	
	var OPTION_FONT = "Verdana";
	var OPTION_FONT_SIZE = 25;
	var OPTION_FONT_COLOR_R = 190;
	var OPTION_FONT_COLOR_G = 240;
	var OPTION_FONT_COLOR_B = 255;
	
	
	var OPTION_SOUND_TEXT_X = 640;
	var OPTION_SOUND_TEXT_Y = 180;
	var OPTION_SOUND_TEXT_W = 300;
	
	var OPTION_MUSIC_TEXT_X = 640;
	var OPTION_MUSIC_TEXT_Y = 280;
	var OPTION_MUSIC_TEXT_W = 300;
	
	var OPTION_GRAPHIC_TEXT_X = 640;
	var OPTION_GRAPHIC_TEXT_Y = 380;
	var OPTION_GRAPHIC_TEXT_W = 300;
	
	
	
	var BUTTON_SXU = 0;
	var BUTTON_SYU = 0;
	var BUTTON_SXD = 0;
	var BUTTON_SYD = 75;
	var BUTTON_SW = 145;
	var BUTTON_SH = 75;
	
	var SAVE_BUTTON_DX = 460;
	var SAVE_BUTTON_DY = 540;
	var SAVE_BUTTON_DW = 145;
	var SAVE_BUTTON_DH = 75;
	
	var CANCEL_BUTTON_DX = 680;
	var CANCEL_BUTTON_DY = 540;
	var CANCEL_BUTTON_DW = 145;
	var CANCEL_BUTTON_DH = 75;
	
	var saveButton;
	var cancelButton;
	
	
	var SOUND_BAR_X = 460;
	var SOUND_BAR_Y = 200;
	var SOUND_BAR_W = 365;
	var SOUND_BAR_H =  30;
	
	var MUSIC_BAR_X = 460;
	var MUSIC_BAR_Y = 300;
	var MUSIC_BAR_W = 365;
	var MUSIC_BAR_H =  30;
	
	
	var GRAPHIC_QUALITY_FONT = "Verdana";
	var GRAPHIC_QUALITY_FONT_SIZE = 17;
	
	var GRAPHIC_QUALITY_FONT_COLOR_R_DARK = 20;
	var GRAPHIC_QUALITY_FONT_COLOR_G_DARK = 40;
	var GRAPHIC_QUALITY_FONT_COLOR_B_DARK = 60;
	
	var GRAPHIC_QUALITY_FONT_COLOR_R_BRIGHT = 80;
	var GRAPHIC_QUALITY_FONT_COLOR_G_BRIGHT = 120;
	var GRAPHIC_QUALITY_FONT_COLOR_B_BRIGHT = 160;
	
	var GRAPHIC_BUTTON_LOW_X = 460;
	var GRAPHIC_BUTTON_MED_X = 590;
	var GRAPHIC_BUTTON_HIG_X = 720;
	var GRAPHIC_BUTTON_Y = 400;
	var GRAPHIC_BUTTON_W = 110;
	var GRAPHIC_BUTTON_H = 55;
	
	var GRAPHIC_QUALITY_TEXT_LOW_X = 510;
	var GRAPHIC_QUALITY_TEXT_LOW_Y = 425;
	var GRAPHIC_QUALITY_TEXT_MED_X = 640;
	var GRAPHIC_QUALITY_TEXT_MED_Y = 425;
	var GRAPHIC_QUALITY_TEXT_HIG_X = 770;
	var GRAPHIC_QUALITY_TEXT_HIG_Y = 425;
	
	
	
	
	var invoker = 0;  // 0 = Invoked from Main Menu
					  // 1 = Invoked from Game Play
					  
	var panelAlpha = 0;
	
	
	var barHolding = 0;
	var soundVolume = 0;
	var musicVolume = 0;
	var qualitySetting = 0;
	
	this.Init = function () {
		// Image
		splashImageHandle = g_graphicEngine.LoadImage("Data/MainMenu/MainBG.jpg");
		panelImageHandle = g_graphicEngine.LoadImage("Data/MainMenu/GSOption/Panel.png");
		qualityButtonHandle = g_graphicEngine.LoadImage("Data/MainMenu/GSOption/QualityButton.png");
		progressBarImageHandle = g_graphicEngine.LoadImage("Data/MainMenu/GSOption/SoundBar.png");
		
		// Button
		saveButton = new Button();
		saveButton.LoadImage("Data/MainMenu/GSOption/SaveButton.png", BUTTON_SXU, BUTTON_SYU, BUTTON_SXD, BUTTON_SYD, BUTTON_SW, BUTTON_SH);
		saveButton.SetPosition (SAVE_BUTTON_DX, SAVE_BUTTON_DY, SAVE_BUTTON_DW, SAVE_BUTTON_DH);
		saveButton.RegisterFunction(SaveAndQuit);
		
		// Button
		cancelButton = new Button();
		cancelButton.LoadImage("Data/MainMenu/GSOption/CancelButton.png", BUTTON_SXU, BUTTON_SYU, BUTTON_SXD, BUTTON_SYD, BUTTON_SW, BUTTON_SH);
		cancelButton.SetPosition (CANCEL_BUTTON_DX, CANCEL_BUTTON_DY, CANCEL_BUTTON_DW, CANCEL_BUTTON_DH);
		cancelButton.RegisterFunction(Quit);
	}
	
	this.Update = function () {
		if (invoker == 1) {
			if (panelAlpha < 1) {
				panelAlpha += g_deltaTime * 0.001 * FADE_SPEED;
				if (panelAlpha > 1) panelAlpha = 1;
			}
		}
		else if (invoker == -1) {
			if (panelAlpha > 0) {
				panelAlpha -= g_deltaTime * 0.001 * FADE_SPEED;
				if (panelAlpha < 0) {
					panelAlpha = 0;
					g_gsGamePlay.ReturnFromOptionScreen();
					SwitchState (g_gsGamePlay, false);
				}
			}
		}
	}
	
	this.Draw = function () {
		if (invoker == 0) {
			g_graphicEngine.DrawFast (g_context, splashImageHandle, 0, 0);
			g_graphicEngine.FillCanvas (g_context, BACKGROUND_BLUR_R, BACKGROUND_BLUR_G, BACKGROUND_BLUR_B, BACKGROUND_BLUR_ALPHA, 0, 0, CANVAS_W, CANVAS_H);
		}
		else if (invoker == 1 || invoker == -1) {
			g_gsGamePlay.Draw();
		}
		
		g_graphicEngine.SetGlobalAlpha (panelAlpha);
		
		// Panel
		g_graphicEngine.DrawFast (g_context, panelImageHandle, PANEL_X, PANEL_Y);
		
		// Text
		g_graphicEngine.DrawTextRGB (g_context, TEXT_SOUND_VOLUME, OPTION_SOUND_TEXT_X + 2, OPTION_SOUND_TEXT_Y + 2, OPTION_SOUND_TEXT_W, OPTION_FONT, OPTION_FONT_SIZE, true, false, "center", "middle", OPTION_FONT_COLOR_R * 0.2, OPTION_FONT_COLOR_G * 0.2, OPTION_FONT_COLOR_B * 0.2, 1);
		g_graphicEngine.DrawTextRGB (g_context, TEXT_SOUND_VOLUME, OPTION_SOUND_TEXT_X, OPTION_SOUND_TEXT_Y, OPTION_SOUND_TEXT_W, OPTION_FONT, OPTION_FONT_SIZE, true, false, "center", "middle", OPTION_FONT_COLOR_R, OPTION_FONT_COLOR_G, OPTION_FONT_COLOR_B, 1);
		
		g_graphicEngine.DrawTextRGB (g_context, TEXT_MUSIC_VOLUME, OPTION_MUSIC_TEXT_X + 2, OPTION_MUSIC_TEXT_Y + 2, OPTION_MUSIC_TEXT_W, OPTION_FONT, OPTION_FONT_SIZE, true, false, "center", "middle", OPTION_FONT_COLOR_R * 0.2, OPTION_FONT_COLOR_G * 0.2, OPTION_FONT_COLOR_B * 0.2, 1);
		g_graphicEngine.DrawTextRGB (g_context, TEXT_MUSIC_VOLUME, OPTION_MUSIC_TEXT_X, OPTION_MUSIC_TEXT_Y, OPTION_MUSIC_TEXT_W, OPTION_FONT, OPTION_FONT_SIZE, true, false, "center", "middle", OPTION_FONT_COLOR_R, OPTION_FONT_COLOR_G, OPTION_FONT_COLOR_B, 1);
		
		g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY, OPTION_GRAPHIC_TEXT_X + 2, OPTION_GRAPHIC_TEXT_Y + 2, OPTION_GRAPHIC_TEXT_W, OPTION_FONT, OPTION_FONT_SIZE, true, false, "center", "middle", OPTION_FONT_COLOR_R * 0.2, OPTION_FONT_COLOR_G * 0.2, OPTION_FONT_COLOR_B * 0.2, 1);
		g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY, OPTION_GRAPHIC_TEXT_X, OPTION_GRAPHIC_TEXT_Y, OPTION_GRAPHIC_TEXT_W, OPTION_FONT, OPTION_FONT_SIZE, true, false, "center", "middle", OPTION_FONT_COLOR_R, OPTION_FONT_COLOR_G, OPTION_FONT_COLOR_B, 1);
		
		// Quality option button
		if (qualitySetting == 0 || barHolding == 3) {
			g_graphicEngine.Draw (g_context, qualityButtonHandle, 0, 0, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_LOW_X, GRAPHIC_BUTTON_Y, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H);
			g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY_LOW, GRAPHIC_QUALITY_TEXT_LOW_X, GRAPHIC_QUALITY_TEXT_LOW_Y, GRAPHIC_BUTTON_W, GRAPHIC_QUALITY_FONT, GRAPHIC_QUALITY_FONT_SIZE, true, false, "center", "middle", GRAPHIC_QUALITY_FONT_COLOR_R_BRIGHT, GRAPHIC_QUALITY_FONT_COLOR_G_BRIGHT, GRAPHIC_QUALITY_FONT_COLOR_B_BRIGHT, 1);
		}
		else {
			g_graphicEngine.Draw (g_context, qualityButtonHandle, 0, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_LOW_X, GRAPHIC_BUTTON_Y, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H);
			g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY_LOW, GRAPHIC_QUALITY_TEXT_LOW_X, GRAPHIC_QUALITY_TEXT_LOW_Y, GRAPHIC_BUTTON_W, GRAPHIC_QUALITY_FONT, GRAPHIC_QUALITY_FONT_SIZE, true, false, "center", "middle", GRAPHIC_QUALITY_FONT_COLOR_R_DARK, GRAPHIC_QUALITY_FONT_COLOR_G_DARK, GRAPHIC_QUALITY_FONT_COLOR_B_DARK, 1);
		}
		
		if (qualitySetting == 1 || barHolding == 4) {
			g_graphicEngine.Draw (g_context, qualityButtonHandle, 0, 0, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_MED_X, GRAPHIC_BUTTON_Y, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H);
			g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY_MEDIUM, GRAPHIC_QUALITY_TEXT_MED_X, GRAPHIC_QUALITY_TEXT_MED_Y, GRAPHIC_BUTTON_W, GRAPHIC_QUALITY_FONT, GRAPHIC_QUALITY_FONT_SIZE, true, false, "center", "middle", GRAPHIC_QUALITY_FONT_COLOR_R_BRIGHT, GRAPHIC_QUALITY_FONT_COLOR_G_BRIGHT, GRAPHIC_QUALITY_FONT_COLOR_B_BRIGHT, 1);
		}
		else {
			g_graphicEngine.Draw (g_context, qualityButtonHandle, 0, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_MED_X, GRAPHIC_BUTTON_Y, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H);
			g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY_MEDIUM, GRAPHIC_QUALITY_TEXT_MED_X, GRAPHIC_QUALITY_TEXT_MED_Y, GRAPHIC_BUTTON_W, GRAPHIC_QUALITY_FONT, GRAPHIC_QUALITY_FONT_SIZE, true, false, "center", "middle", GRAPHIC_QUALITY_FONT_COLOR_R_DARK, GRAPHIC_QUALITY_FONT_COLOR_G_DARK, GRAPHIC_QUALITY_FONT_COLOR_B_DARK, 1);
		}
		
		if (qualitySetting == 2 || barHolding == 5) {
			g_graphicEngine.Draw (g_context, qualityButtonHandle, 0, 0, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_HIG_X, GRAPHIC_BUTTON_Y, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H);
			g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY_HIGH, GRAPHIC_QUALITY_TEXT_HIG_X, GRAPHIC_QUALITY_TEXT_HIG_Y, GRAPHIC_BUTTON_W, GRAPHIC_QUALITY_FONT, GRAPHIC_QUALITY_FONT_SIZE, true, false, "center", "middle", GRAPHIC_QUALITY_FONT_COLOR_R_BRIGHT, GRAPHIC_QUALITY_FONT_COLOR_G_BRIGHT, GRAPHIC_QUALITY_FONT_COLOR_B_BRIGHT, 1);
		}
		else {
			g_graphicEngine.Draw (g_context, qualityButtonHandle, 0, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H, GRAPHIC_BUTTON_HIG_X, GRAPHIC_BUTTON_Y, GRAPHIC_BUTTON_W, GRAPHIC_BUTTON_H);
			g_graphicEngine.DrawTextRGB (g_context, TEXT_GRAPHIC_QUALITY_HIGH, GRAPHIC_QUALITY_TEXT_HIG_X, GRAPHIC_QUALITY_TEXT_HIG_Y, GRAPHIC_BUTTON_W, GRAPHIC_QUALITY_FONT, GRAPHIC_QUALITY_FONT_SIZE, true, false, "center", "middle", GRAPHIC_QUALITY_FONT_COLOR_R_DARK, GRAPHIC_QUALITY_FONT_COLOR_G_DARK, GRAPHIC_QUALITY_FONT_COLOR_B_DARK, 1);
		}
	
		
		
		// Bar
		g_graphicEngine.Draw (g_context, progressBarImageHandle, (soundVolume * SOUND_BAR_W) >> 0, 0, (SOUND_BAR_W * (1 - soundVolume)) >> 0, SOUND_BAR_H, SOUND_BAR_X + (soundVolume * SOUND_BAR_W) >> 0, SOUND_BAR_Y, (SOUND_BAR_W * (1 - soundVolume)) >> 0, SOUND_BAR_H);
		g_graphicEngine.Draw (g_context, progressBarImageHandle, 0, SOUND_BAR_H, (SOUND_BAR_W * soundVolume) >> 0, SOUND_BAR_H, SOUND_BAR_X, SOUND_BAR_Y, (SOUND_BAR_W * soundVolume) >> 0, SOUND_BAR_H);
		
		g_graphicEngine.Draw (g_context, progressBarImageHandle, (musicVolume * MUSIC_BAR_W) >> 0, 0, (MUSIC_BAR_W * (1 - musicVolume)) >> 0, MUSIC_BAR_H, MUSIC_BAR_X + (musicVolume * MUSIC_BAR_W) >> 0, MUSIC_BAR_Y, (MUSIC_BAR_W * (1 - musicVolume)) >> 0, MUSIC_BAR_H);
		g_graphicEngine.Draw (g_context, progressBarImageHandle, 0, MUSIC_BAR_H, (MUSIC_BAR_W * musicVolume) >> 0, MUSIC_BAR_H, MUSIC_BAR_X, MUSIC_BAR_Y, (MUSIC_BAR_W * musicVolume) >> 0, MUSIC_BAR_H);
		
		
		// Button
		saveButton.Draw();
		cancelButton.Draw();
		
		g_graphicEngine.SetGlobalAlpha (1);
	}
	
	
	this.OnSwitch = function () {
		
	}
	
	this.OnMouseMove = function (x, y) {
		if (barHolding == 0) {
			saveButton.OnMouseMove (x, y);
			cancelButton.OnMouseMove (x, y);
		}
		
		CheckMouseOverBar (x, y);
		
		if (barHolding >= 3) {
			if (x >= GRAPHIC_BUTTON_LOW_X && x <= GRAPHIC_BUTTON_LOW_X + GRAPHIC_BUTTON_W
			&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
				barHolding = 3;
			}
			else if (x >= GRAPHIC_BUTTON_MED_X && x <= GRAPHIC_BUTTON_MED_X + GRAPHIC_BUTTON_W
			&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
				barHolding = 4;
			}
			else if (x >= GRAPHIC_BUTTON_HIG_X && x <= GRAPHIC_BUTTON_HIG_X + GRAPHIC_BUTTON_W
			&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
				barHolding = 5;
			}
			else {
				barHolding = 0;
			}
		}
	}
	
	this.OnMouseDown = function (x, y) {
		if (x >= SOUND_BAR_X && x <= SOUND_BAR_X + SOUND_BAR_W
		&&  y >= SOUND_BAR_Y && y <= SOUND_BAR_Y + SOUND_BAR_H) {
			barHolding = 1;
		}
		else if (x >= MUSIC_BAR_X && x <= MUSIC_BAR_X + MUSIC_BAR_W
		&&       y >= MUSIC_BAR_Y && y <= MUSIC_BAR_Y + MUSIC_BAR_H) {
			barHolding = 2;
		}
		else if (x >= GRAPHIC_BUTTON_LOW_X && x <= GRAPHIC_BUTTON_LOW_X + GRAPHIC_BUTTON_W
		&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
			barHolding = 3;
		}
		else if (x >= GRAPHIC_BUTTON_MED_X && x <= GRAPHIC_BUTTON_MED_X + GRAPHIC_BUTTON_W
		&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
			barHolding = 4;
		}
		else if (x >= GRAPHIC_BUTTON_HIG_X && x <= GRAPHIC_BUTTON_HIG_X + GRAPHIC_BUTTON_W
		&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
			barHolding = 5;
		}
		
		
		
		CheckMouseOverBar (x, y);
		
		if (barHolding == 0) {
			saveButton.OnMouseDown (x, y);
			cancelButton.OnMouseDown (x, y);
		}
	}
	
	this.OnMouseUp = function (x, y) {
		if (barHolding == 0) {
			saveButton.OnMouseUp (x, y);
			cancelButton.OnMouseUp (x, y);
		}
		
		CheckMouseOverBar (x, y);
		
		if (x >= GRAPHIC_BUTTON_LOW_X && x <= GRAPHIC_BUTTON_LOW_X + GRAPHIC_BUTTON_W
		&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
			qualitySetting = 0;
		}
		else if (x >= GRAPHIC_BUTTON_MED_X && x <= GRAPHIC_BUTTON_MED_X + GRAPHIC_BUTTON_W
		&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
			qualitySetting = 1;
		}
		else if (x >= GRAPHIC_BUTTON_HIG_X && x <= GRAPHIC_BUTTON_HIG_X + GRAPHIC_BUTTON_W
		&&       y >= GRAPHIC_BUTTON_Y && y <= GRAPHIC_BUTTON_Y + GRAPHIC_BUTTON_H) {
			qualitySetting = 2;
		}
	
		barHolding = 0;
	}
	
	this.OnMouseWheel = function (delta) {
	
	}
	
	this.OnKeyDown = function (keycode) {
	
	}
	
	this.OnKeyUp = function (keycode) {
	
	}
	
	
	var CheckMouseOverBar = function (x, y) {
		if (barHolding == 1) {
			soundVolume = (x - SOUND_BAR_X) / SOUND_BAR_W;
			if (soundVolume < 0) soundVolume = 0;
			if (soundVolume > 1) soundVolume = 1;
		}
		else if (barHolding == 2) {
			musicVolume = (x - MUSIC_BAR_X) / MUSIC_BAR_W;
			if (musicVolume < 0) musicVolume = 0;
			if (musicVolume > 1) musicVolume = 1;
		}
	}
	
	
	this.InvokeFromMainMenu = function () {
		invoker = 0;
		panelAlpha = 1;
		soundVolume = g_userProfile.m_soundVolume;
		musicVolume = g_userProfile.m_musicVolume;
		qualitySetting = g_userProfile.m_graphicQuality;
	}
	
	this.InvokeFromGamePlay = function () {
		invoker = 1;
		panelAlpha = 0;
	}
	
	
	var SaveAndQuit = function () {
		g_userProfile.m_soundVolume = soundVolume;
		g_userProfile.m_musicVolume = musicVolume;
		g_userProfile.m_graphicQuality = qualitySetting;
		g_userProfile.Save();
		
		Quit();
	}
	
	var Quit = function () {
		if (invoker == 0) {
			SwitchState (g_gsMainMenu, true);
		}
		else if (invoker == 1) {
			invoker = -1;
		}
	}
}